<?php
/**
 * Created by PhpStorm.
 * User: chenyuz
 * Date: 2019/3/5
 * Time: 15:41
 */
namespace app\ops\controller;

use think\Db;

class User extends Base{
    public function index() {

        $order = request()->get('order', "create_time");

        $list = Db::name("customer")->field(["id", "nickname", "avatar_url", "city", "province", "country", "money", "tiger_tee", "code", "create_time"])->where(['type'=> 1])->order("$order desc")->paginate(10, false, [
            'query'=> [
                'order'=> $order
            ]
        ]);
        $this->assign("list", $list);
        return $this->fetch();
    }

    function company(){
        $list = Db::name("company")->field(["id", "account", "mobile", "address", "tel", "status", "create_time", "wx_number", "qrcode"])->order("create_time desc")->paginate(10);
        $this->assign("list", $list);
        return $this->fetch();
    }

    function detail(){
        $id = \request()->param('id', 0);

        $where = [
            'm.u_id'=> $id,
        ];

        $list = db('money_log m')
            ->join('customer c', 'm.child_id = c.id', 'left')
            ->where($where)
            ->field('m.id, c.avatar_url, c.nickname, m.create_time, m.type, m.value, m.reason, m.reason_type')
            ->order('m.id desc')
            ->paginate(10, false, ['query'=> ['id'=> $id]]);

        $data = Db::name("customer")->field(["id", "nickname", "money", "tiger_tee", "code", "address"])->where(['id'=> $id])->find();
        $this->assign("data", $data);

        $this->assign('list', $list);

        return $this->fetch();
    }
}